///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_IO_GLOB_H_
#define _BUOLA_IO_GLOB_H_

#include <buola/buola.h>

namespace buola { namespace io {

///\addtogroup io
///@{

enum EGlob
{
    GLOB_NONE=0,
    GLOB_BRACES=(1<<0),     ///< perform brace expansion
    GLOB_TILDES=(1<<1),     ///< perform tilde expansion
    GLOB_NOGLOB=(1<<2),     ///< pattern doesn't contain any glob expression
    GLOB_NOESCAPE=(1<<3),   ///< pattern doesn't contain any escaped character
    GLOB_ONLYDIR=(1<<4),    ///< match only directories
    GLOB_NODIR=(1<<5),      ///< don't match directories
    GLOB_ONLYEXEC=(1<<6),   ///< match only executable files
    GLOB_MATCHPERIOD=(1<<7),///< allow a wildcard to match an initial period
    GLOB_MARKDIRS=(1<<8),   ///< mark directories with a trailing /
    GLOB_KEEPTILDE=(1<<9),  ///< if tilde expansion is performed, replace the tilde back in results
    GLOB_SORT=(1<<10),      ///< sort files
    
    GLOB_MUSTCHECK=GLOB_ONLYDIR|GLOB_NODIR|GLOB_ONLYEXEC|GLOB_MARKDIRS,
    GLOB_FULLCHECK=GLOB_ONLYEXEC
};

DECLARE_ENUM_BITOPS(EGlob)

bool glob_match(const std::string &pSrc,const std::string &pGlob);
void expand_braces(const std::string &pPattern,std::vector<std::string> &pDst);
int expand_tilde(const std::string &pSrc,std::string &pDst);
void glob_unescape(const std::string &pSrc,std::string &pDst);
void glob_in_dir(const std::string &pDir,const std::string &pPattern,EGlob pFlags,std::vector<std::string> &pResult);
void glob(const std::string &pPattern,EGlob pFlags,std::vector<std::string> &pResult);
void glob_prefixed(const std::string &pPrefix,const std::string &pPattern,EGlob pFlags,std::vector<std::string> &pResult);
    
///@}

/*namespace io*/ } /*namespace buola*/ }

#endif
